package com.bwie.controller;

import com.alibaba.fastjson.JSONObject;
import com.bwie.pojo.vo.DemoVo;
import com.bwie.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/demo")
public class DemoController {
    @Autowired
    private DemoService demoService;




    @RequestMapping("toDemo")
    public String toDemo(Model model){
        //日收入
        List<DemoVo> list = demoService.getListDayMoney();
        ArrayList<HashMap<String, Object>> hashMaps = new ArrayList<>();
        for (DemoVo demoVo : list) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("value",demoVo.getPrice());
            map.put("name",demoVo.getType());

            hashMaps.add(map);
        }
        model.addAttribute("dayMoney", JSONObject.toJSONString(hashMaps));

        //月收入
        List<Map<String,Object>> list1 = demoService.getListMonthMoney();
        model.addAttribute("monthMoney",JSONObject.toJSONString(list1));


        //近30天收入折线

        ArrayList<String> list3 = new ArrayList<>();
        ArrayList<BigDecimal> list4 = new ArrayList<>();
        List<DemoVo> list2 = demoService.getListByDate();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for (DemoVo demoVo : list2) {
            list3.add(sdf.format(demoVo.getDate()));
            list4.add(demoVo.getPrice());
        }
        model.addAttribute("list3",JSONObject.toJSONString(list3));
        model.addAttribute("list4",JSONObject.toJSONString(list4));

        //订单统计
        List<Date> dateList = demoService.getListMonthDate();
        List<Integer>  sumList= demoService.getSumOrder();
        List<Integer> okList = demoService.getOkOrder();
        List<Integer> notList = demoService.getNotOrder();

        model.addAttribute("dateList",JSONObject.toJSONString(dateList));
        model.addAttribute("sumList",JSONObject.toJSONString(sumList));
        model.addAttribute("okList",JSONObject.toJSONString(okList));
        model.addAttribute("notList",JSONObject.toJSONString(notList));
        return "/demo/demo";
    }
}
